package com.hz.foodstalls.services;

import com.jfinal.aop.Before;
import com.jfinal.aop.Enhancer;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.plugin.ehcache.CacheKit;
import com.hz.foodstalls.model.Admin;
import com.hz.foodstalls.model.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.UUID;

/**
 * Created by foodstalls on 2016/2/17.
 */
public class DemoService {
    private static Logger log = LoggerFactory.getLogger(DemoService.class);
    public static final DemoService service = Enhancer.enhance(DemoService.class);

    @Before(Tx.class)
    public boolean register() {
        // 如果使用TxByMethodRegex之外的需要做事务控制的，可以使用这种services的方式进行
        // 操作数据库表1
        // 操作数据库表2
        // 返回操作结果
        boolean a = Admin.dao.findFirst("select * from admin").set("loginFailureCount", 0).update();

        boolean b = new Resource().set("id", UUID.randomUUID().toString().replace("-", "")).save();
        return a && b;
    }

    @Before(Tx.class)
    public boolean usersave() {
        log.info("in DemoService.usersave function.");
        boolean a = Admin.dao.findFirst("select * from admin").set("loginFailureCount", 2).update();
        boolean b =new Resource().set("id", UUID.randomUUID().toString().replace("-", "")).set("isSystem",0).set("orderList","1").set("value","admin1").save();
        return a && b;
    }
}
